import * as api from '@/api/permission'
import allRoutes from '@/router/generateRoutes'
import recursionRoutes from '@/router/recursionRoutes'
import dynamicRoutes from '@/router/dynamicRoutes'
import router from '@/utils/routerGuard'
let routes = allRoutes.find(item=>item.name === 'home')
export default ({
    namespaced:true,
    state: {
        userMenu:[],
        bread:[]
    },
    getters: {},
    mutations: {
        //#设置用户菜单
        SET_MENU_LIST(state,payload){
            state.userMenu = [...payload]
            // console.log('dynamicRoutes',dynamicRoutes);
            dynamicRoutes.children = [...dynamicRoutes.children,...payload]
            router.addRoute(dynamicRoutes)
        },
        //#获取面包屑
        GET_BREAD(state,payload){
            state.bread = payload
        }
    },
    actions: {
        //#获取远程菜单
        FETCH_MENU_LIST({commit}){
            return api.getMenuListApi()
            .then(res=>{
                // console.log(res.data.menuList);
               let userMenu = recursionRoutes(res.data.menuList,routes.children)
            //    console.log('123123',userMenu);
               commit('SET_MENU_LIST',userMenu)
            })
        }
    },
    modules: {
      
    },
});